{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Demo 01 零售消费数据案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data = pd.read_csv('data/online_retail.csv', encoding='utf-8', dtype={'CustomerID':str})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "  InvoiceNo StockCode                          Description  Quantity  \\\n0    536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n1    536365     71053                  WHITE METAL LANTERN         6   \n2    536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n3    536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n4    536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n\n    InvoiceDate  UnitPrice CustomerID         Country  \n0  12/1/10 8:26       2.55      17850  United Kingdom  \n1  12/1/10 8:26       3.39      17850  United Kingdom  \n2  12/1/10 8:26       2.75      17850  United Kingdom  \n3  12/1/10 8:26       3.39      17850  United Kingdom  \n4  12/1/10 8:26       3.39      17850  United Kingdom  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>InvoiceNo</th>\n      <th>StockCode</th>\n      <th>Description</th>\n      <th>Quantity</th>\n      <th>InvoiceDate</th>\n      <th>UnitPrice</th>\n      <th>CustomerID</th>\n      <th>Country</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>536365</td>\n      <td>85123A</td>\n      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n      <td>6</td>\n      <td>12/1/10 8:26</td>\n      <td>2.55</td>\n      <td>17850</td>\n      <td>United Kingdom</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>536365</td>\n      <td>71053</td>\n      <td>WHITE METAL LANTERN</td>\n      <td>6</td>\n      <td>12/1/10 8:26</td>\n      <td>3.39</td>\n      <td>17850</td>\n      <td>United Kingdom</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>536365</td>\n      <td>84406B</td>\n      <td>CREAM CUPID HEARTS COAT HANGER</td>\n      <td>8</td>\n      <td>12/1/10 8:26</td>\n      <td>2.75</td>\n      <td>17850</td>\n      <td>United Kingdom</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>536365</td>\n      <td>84029G</td>\n      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n      <td>6</td>\n      <td>12/1/10 8:26</td>\n      <td>3.39</td>\n      <td>17850</td>\n      <td>United Kingdom</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>536365</td>\n      <td>84029E</td>\n      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n      <td>6</td>\n      <td>12/1/10 8:26</td>\n      <td>3.39</td>\n      <td>17850</td>\n      <td>United Kingdom</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "online_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 240007 entries, 0 to 240006\n",
      "Data columns (total 8 columns):\n",
      " #   Column       Non-Null Count   Dtype  \n",
      "---  ------       --------------   -----  \n",
      " 0   InvoiceNo    240007 non-null  object \n",
      " 1   StockCode    240007 non-null  object \n",
      " 2   Description  239106 non-null  object \n",
      " 3   Quantity     240007 non-null  int64  \n",
      " 4   InvoiceDate  240007 non-null  object \n",
      " 5   UnitPrice    240007 non-null  float64\n",
      " 6   CustomerID   172782 non-null  object \n",
      " 7   Country      240007 non-null  object \n",
      "dtypes: float64(1), int64(1), object(6)\n",
      "memory usage: 14.6+ MB\n"
     ]
    }
   ],
   "source": [
    "online_data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data.apply(lambda x: sum(x.isnull())) # 1 统计 空值\n",
    "online_data.drop(['Description'], axis=1, inplace=True) # 2 删除不必要的列\n",
    "online_data['CustomerID'] = online_data['CustomerID'].fillna('U') # 3 对某列的控制进行填充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# online_data[online_data['InvoiceNo'].str[0]=='C'] # 退货订单C开头"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data['amount'] = online_data['Quantity'] * online_data['UnitPrice'] # 金额 = 单价*数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data['date'] = [x.split(' ')[0] for x in online_data['InvoiceDate']]\n",
    "online_data['time'] = [x.split(' ')[1] for x in online_data['InvoiceDate']]\n",
    "online_data.drop(['InvoiceDate'], axis = 1, inplace=True) # 删除 InvoiceDate列\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data['month']  = [x.split('/')[0] for x in online_data['date']]\n",
    "online_data['day']    = [x.split('/')[1] for x in online_data['date']]\n",
    "online_data['year']   = [x.split('/')[2] for x in online_data['date']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data['date'] = pd.to_datetime(online_data['date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "online_data = online_data.drop_duplicates() # 删除重复值"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 数据分析"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "online_data.describe() # 查看基本的描述统计"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'online_data' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-1-ddbeff175fe6>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mcountry_result\u001B[0m  \u001B[0;34m=\u001B[0m \u001B[0monline_data\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mloc\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0monline_data\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'Quantity'\u001B[0m\u001B[0;34m]\u001B[0m \u001B[0;34m>\u001B[0m \u001B[0;36m0\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mgroupby\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'Country'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msum\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'Quantity'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msort_values\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mascending\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mFalse\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mhead\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;36m10\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      2\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      3\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      4\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      5\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mNameError\u001B[0m: name 'online_data' is not defined"
     ]
    }
   ],
   "source": [
    "# 购买商品前十的国家\n",
    "country_result  = online_data.loc[online_data['Quantity'] > 0].groupby('Country').sum()['Quantity'].sort_values(ascending=False).head(10)\n",
    "country_amount_result  = online_data.loc[online_data['amount'] > 0].groupby('Country').sum()['amount'].sort_values(ascending=False).head(10)\n",
    "\n",
    "online_data.describe() # 查看基本的描述统计\n",
    "online_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "sell_data = online_data.loc[online_data['Quantity'] >= 0]\n",
    "df2 = online_data.loc[online_data['UnitPrice'] == 0] # 考虑是否删除 售价为0 或 < 0的商品"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. 数据分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "data1 = online_data.loc[online_data['Quantity'] <= 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "month          1        12         2         3         4         5         6\nyear                                                                        \n10           NaN -74729.12       NaN       NaN       NaN       NaN       NaN\n11    -131363.05       NaN -25519.15 -34201.28 -44600.65 -47202.51 -67292.23",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th>month</th>\n      <th>1</th>\n      <th>12</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n    </tr>\n    <tr>\n      <th>year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10</th>\n      <td>NaN</td>\n      <td>-74729.12</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>-131363.05</td>\n      <td>NaN</td>\n      <td>-25519.15</td>\n      <td>-34201.28</td>\n      <td>-44600.65</td>\n      <td>-47202.51</td>\n      <td>-67292.23</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table = pd.pivot_table(data1, index='year',columns='month', values='amount', aggfunc={'amount': np.sum})\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2 = online_data.loc[(online_data['Quantity'] > 0) & (online_data['UnitPrice']) > 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "month          1         12          2          3           4          5  \\\nyear                                                                       \n10           NaN  821452.73        NaN        NaN         NaN        NaN   \n11     689811.61        NaN  522545.56  716215.26  536968.491  769281.76   \n\nmonth          6  \nyear              \n10           NaN  \n11     634639.35  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th>month</th>\n      <th>1</th>\n      <th>12</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n    </tr>\n    <tr>\n      <th>year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10</th>\n      <td>NaN</td>\n      <td>821452.73</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>689811.61</td>\n      <td>NaN</td>\n      <td>522545.56</td>\n      <td>716215.26</td>\n      <td>536968.491</td>\n      <td>769281.76</td>\n      <td>634639.35</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table2 = pd.pivot_table(data2, index='year',columns='month', values='amount', aggfunc={'amount': np.sum})\n",
    "table2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "month         1        12         2         3        4         5         6\nyear                                                                      \n10          NaN  0.090972       NaN       NaN      NaN       NaN       NaN\n11     0.190433       NaN  0.048836  0.047753  0.08306  0.061359  0.106032",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th>month</th>\n      <th>1</th>\n      <th>12</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n    </tr>\n    <tr>\n      <th>year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>10</th>\n      <td>NaN</td>\n      <td>0.090972</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>0.190433</td>\n      <td>NaN</td>\n      <td>0.048836</td>\n      <td>0.047753</td>\n      <td>0.08306</td>\n      <td>0.061359</td>\n      <td>0.106032</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.abs(table /table2) # 根据月份 求 退货率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "0.08957896009798133"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.abs(table /table2).loc['11'].mean()  # 某年的平均 退货率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4用户分类RFM模型\n",
    "R 最近一次消费时间 Recency\n",
    "F 消费次数 Frequency\n",
    "M 消费金额 Monetary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_value = data2.groupby('CustomerID')['date'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "Timestamp('2011-06-26 00:00:00')"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2['date'].max()  # 最后购买日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_value = (data2['date'].max() - r_value).dt.days # 某个客户最后一次的时间(消费天数)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_value = data2.groupby('CustomerID')['InvoiceNo'].nunique() # 消费频次 根据订单编号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "m_value = data2.groupby('CustomerID')['amount'].sum() # 消费总金额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "count    2932.000000\nmean       70.434857\nstd        59.189570\nmin         0.000000\n25%        20.000000\n50%        51.000000\n75%       109.000000\nmax       207.000000\nName: date, dtype: float64"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_value.describe() # 差距大不大 看均值和中位数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOXElEQVR4nO3dUYxc1X3H8e+vCc1DQALK1nKN06WR80Aq1YlWgBRUEUUNwVRy8oLMQ+JESM6DkRIpD3GSh/CC5EoF1KgNkiMQUNEQpARhCdSGWImiPCSwRi5guzROYoQtYztNBFSRaIF/H+ZaTO1dZnZnZ2f27PcjjebOuffu/H10/du7Z869k6pCktSWP5p0AZKklWe4S1KDDHdJapDhLkkNMtwlqUHvnXQBAFdccUXNzs5OugxJWlMOHjz426qaWWjdVIT77Ows8/Pzky5DktaUJC8tts5hGU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3M8reVw9xYHC0jy/iSXnFsGPgm8QK9vdnab7QQen0yFU2exftkPfK6b5XAd8Grfn9vrznnjw5+hd0xBr592JHlfkqvofWD49GrXt9qSBLgPOFpVd/etmp7jqarW7APYBvwn8CvgG5OuZxoewF8A/949Dp/rF+BP6H16/0vgR8Dlk651An3zXXpDCv9Lb8zztsX6BQi92Vi/Ap4H5iZd/4T76Z+7fniOXlBt7Nv+G10/vQjcNOn6V6mPrqc35PIccKh7bJum48nbD0hSg9bysIwkaRGGuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSgwx3SWrQ/wFhTZSS5ZfuvQAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(r_value, bins=30)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "count      2932.000000\nmean       1599.902715\nstd       15684.606084\nmin           2.900000\n25%         247.637500\n50%         491.885000\n75%        1125.435000\nmax      811120.550000\nName: amount, dtype: float64"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m_value.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAARkElEQVR4nO3df4zkd13H8efLUqoBtK1dL+f1dAsWTf3Dtm5qjWCQKj+KesUftY2RE5scJiWBoNFDEkEjyaECCUFLjrThSpBSBdKLgFAqkfBHi9t6lP6gdluuaS/Xu4UiLUHRlrd/zOdgeuze7uzuzO5+7v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sXfz9wBVJTktyDnAugzdxxlHbs5I859gygzfk7mo1HHu3fSdw01Btr2rv2F8MfH3oX8dxeNqIaiP02dDjjdI/nwRekuSMNiXxkta2ppK8DPgT4Ner6ptD7VMZfG8CSZ7LoH8ebLU9nuTi9jp91dDPspZ1jfq8TfJ39peBL1XVd6ZbJtlfi+UDk36NreZd4fW8MHiH+T8Z/AV+04Qf+wUM/qW6EzjQLpcC7we+2Nr3A1uH9nlTq/U+Vvlu/BK1PZfBkQhfAO4+1jfADwO3APcDnwbObO1h8MUqD7TaZ8ZY27OArwI/NNQ28T5j8MflMPB/DOYxr1pJ/zCYA59rl1ePqa45BvOux15n72nb/mZ7fg8AdwC/NnQ/MwzC9gHg3bQz0de4rpGft7X+nV2ortb+PuAPj9t2kv21WD5M9DXmxw9IUoc267SMJOkEDHdJ6pDhLkkdMtwlqUOGuyR1yHCXpA4Z7pLUof8HQeasv9i5eK4AAAAASUVORK5CYII=\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(m_value[m_value < 2000], bins=30)\n",
    "plt.show() # 均值和中位数 相差太大  存在异常值 ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "0.0      1.0\n0.1      1.0\n0.2      1.0\n0.3      1.0\n0.4      1.0\n0.5      2.0\n0.6      2.0\n0.7      3.0\n0.8      4.0\n0.9      6.0\n1.0    833.0\nName: InvoiceNo, dtype: float64"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f_value.describe()\n",
    "f_value.quantile([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]) # 查看分位数,确定消费频次分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhE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/bqhtTR1nBm9Ix4G/ZDBnfDVwJnAn8Djwh8AZbewkg78Sd3Lb9wFT7fbeVax3isHc98nX8++0sT8KHDzVa2gVa/6v7XX6IIMgP2dmzW39MgZX2H17tWtu7Z8++fodGrsqx9lv5EpSR5zekaSOGPqS1BFDX5I6YuhLUkcMfUnqiKEvSR0x9CWpI4a+JHXk/wGCUplaDkIMvgAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(f_value[f_value<20], bins=30)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_bins = [0,30,90,180,360,720] # 最近一次消费间隔 分类\n",
    "f_bins = [1,2,3,10,20,5000]\n",
    "m_bins = [0,500,2000,5000,10000,20000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_score = pd.cut(r_value,r_bins, labels=[5,4,3,2,1], right=False) # 求r的分数\n",
    "f_score = pd.cut(f_value,f_bins, labels=[1,2,3,4,5], right=False) # 求r的分数\n",
    "m_score = pd.cut(m_value,m_bins, labels=[1,2,3,4,5], right=False) # 求r的分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "rfm = pd.concat([r_score,f_score,m_score], axis =1 ) # 为什么amount 存在缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "rfm.rename(columns={'date':'r_score','InvoiceNo':'f_score','amount':'m_score' }, inplace=True) # 该名称"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in ['r_score', 'f_score','m_score']:\n",
    "    rfm[i] = rfm[i].astype(float) # 类型转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "           r_score      f_score      m_score\ncount  2932.000000  2932.000000  2911.000000\nmean      3.908595     1.918486     1.640330\nstd       0.937396     0.980798     0.779555\nmin       2.000000     1.000000     1.000000\n25%       3.000000     1.000000     1.000000\n50%       4.000000     2.000000     1.000000\n75%       5.000000     3.000000     2.000000\nmax       5.000000     5.000000     5.000000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>r_score</th>\n      <th>f_score</th>\n      <th>m_score</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>2932.000000</td>\n      <td>2932.000000</td>\n      <td>2911.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>3.908595</td>\n      <td>1.918486</td>\n      <td>1.640330</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>0.937396</td>\n      <td>0.980798</td>\n      <td>0.779555</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>2.000000</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>3.000000</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>4.000000</td>\n      <td>2.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>5.000000</td>\n      <td>3.000000</td>\n      <td>2.000000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>5.000000</td>\n      <td>5.000000</td>\n      <td>5.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rfm.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "rfm['R'] = np.where(rfm['r_score'] >3.908,'高','低' ) # 高于均值 就是高价值,否则低价值客户\n",
    "rfm['F'] = np.where(rfm['f_score'] >1.917,'高','低' ) # 高于均值 就是高价值,否则低价值客户\n",
    "rfm['M'] = np.where(rfm['m_score'] >1.640,'高','低' ) # 高于均值 就是高价值,否则低价值客户\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "rfm['value'] = rfm['R'].str[:] + rfm['F'].str[:] + rfm['M'].str[:]\n",
    "rfm['value'] = rfm['value'].str.strip()\n",
    "def trans_value(x):\n",
    "    if x == '高高高':\n",
    "        return '重要价值客户'\n",
    "    if x == '高低高':\n",
    "        return '重要发展客户'\n",
    "    elif x == '底高高':\n",
    "        return '重要保持客户'\n",
    "    else:\n",
    "        return '一般用户'\n",
    "\n",
    "rfm['客户等级'] = rfm['value'].apply(trans_value) # 通过apply 将用户分为8类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD4CAYAAADmWv3KAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUnklEQVR4nO3df5xldX3f8debXdBlMUJkXIVKMbLU0MjGOvJjs+gYIaDUphDNWmhaH8ZulGhIrRZRUouWkGobgqLYrdQiCRii+WFT0IqwdelaZNcUQYPpQ1mEFc1ggQkPCT+WT/84Z7LX4W525u7MLPvl9Xw87mPO/Z5zz4/7PfO+3/P9nrmTqkKS1J599vQOSJIWhgEvSY0y4CWpUQa8JDXKgJekRi3d0zsw7eCDD67DDz98T++GJO1VtmzZcm9VjQ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8Wvo6vnfDsx7ab+OT/XPlwK/k+T+gWV+mu4bVf8qyWuAfavqL0Z4C/Y681xnNyXZAvwh3YfDp+ha/D8HXJLkMLqbG36GrjuIfv5PAVfRdaNemOQrwBuq6hv9Mk3WmbdJzpMk59Bd3t8F/D7dpeApdINzD9C1TC6ja3H84sAtX2fS3aXxFbrL/rOr6n/2J9SbqurnF/dI2tC3qPfIIHR/583jO7vCSvJM4ICq2jZs/lPVXOosybJhjZzBbssk+/Z35/xYVU3NWG7/gfvlm60zA36eJFlaVY8NPN8P2D54wk6P2ifZr6p2NmA7vexeeUJJevIw4CWpUX7ZmCQ1yoCXpEYZ8JLUKANekhr1/wFVWC2siPPgrwAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['font.sans-serif'] = 'SimHei'\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.bar(rfm['客户等级'].value_counts().index, rfm['客户等级'].value_counts().values, color='orange')\n",
    "plt.show() # 绘制 柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARYAAADnCAYAAADb9HlHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAkcUlEQVR4nO3deXxU9b3/8ddntiSTQEAEgiwOCrhUxQURFRSXe21NvbWtW7XWVq3S1qo/b2untd5OtV5jN7Vaa1dtta1a9boN2FZEgeJS0UKoCwqEHWTLQPZk5vv743uAARNIwky+s3yej0ceJDMn53wmTN75buccMcaglFKZ5HNdgFKq8GiwKKUyToNFKZVxGixKqYzTYFFKZZwGi1Iq4zRYlFIZp8GilMo4DRalVMZpsCilMk6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0tIm8Ct3jb1AHXGWNeFJFB2F/oJ0XkUmPMGuyUcQD4EfCttJZC/90OXYK9dvB0YAMQS3vueG8fj3hfB4C7RKQ+bZujsSdlbhORc4CgMUZvhOaATjerXvNaEE5mVryZpFRX3RkRqQQqjDF6qUwHNFiUUhmn5woppTJOg0UplXEaLEqpjNNgUUplnAaLUirjNFiUUhmnwaKUyjgNFqVUxmmwKKUyToNFKZVxGixKqYzTYFFKZZwGi1Iq4zRYlFIZ9/8BH46BUmPs2e8AAAAASUVORK5CYII=\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.pie(rfm['客户等级'].value_counts().values, labels=rfm['客户等级'].value_counts().index, autopct='%1.2f%%',)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 分析结论和建议\n",
    "1 针对退货率, 部分月的退货率比较高??\n",
    "2 用户等级占比.."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}